class PromotionMailer < ActionMailer::Base

  after_action :set_headers

  def promote(promotion_mail, recipients)
    @promotion_mail = promotion_mail
    @recipients = recipients
    background_image = "public/assets/mails/#{@promotion_mail.id}/background.jpg"
    if File.exists? background_image
      attachments.inline['background.jpg'] = File.read(background_image)
      @promotion_mail.html_part.gsub!('$BACKGROUND', attachments['background.jpg'].url)
    end
    mail bcc: @recipients.map(&:email),
         subject: @promotion_mail.subject
  end

  private

  def set_headers
    headers['Return-Path'] = 'abuse@vsc.com'
    headers['X-MAIL-ID'] = @promotion_mail.id
  end

end
